home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 44
/
Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso
/
Aminet
/
comm
/
misc
/
Sashi89.lha
/
Sashi89
/
sources
/
timer.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-05-05
|
2KB
|
103 lines
#include <exec/types.h>
#include <exec/io.h>
#include <exec/memory.h>
#include <devices/timer.h>
#include <proto/exec.h>
#include <proto/alib.h>
#include <proto/dos.h>
#include <stdio.h>
#include "timer.h"
/*struct timerequest *timer_create( ULONG unit );
void timer_delete(struct timerequest *tr );
void timer_waitfor(struct timerequest *tr, struct timeval *tv );*/
/* sleep for 500,000 micro-seconds = 1/2 second */
/*
currentval.tv_secs = 0;
currentval.tv_micro = 500000;
time_delay( ¤tval, UNIT_MICROHZ );
printf( "After 1/2 second delay\n" );
*/
int timer_create( Timer_Info *ti)
{
LONG error;
ti->created = 0;
ti->timerport = CreatePort( 0, 0 );
if ( ti->timerport == NULL )
return( 1 );
ti->TimerIO = (struct timerequest *)
CreateExtIO( ti->timerport, sizeof( struct timerequest ) );
if (ti->TimerIO == NULL )
{
DeletePort(ti->timerport); /* Delete message port */
return( 1 );
}
error = OpenDevice( TIMERNAME, UNIT_MICROHZ,(struct IORequest *) ti->TimerIO, 0L );
if (error != 0 )
{
timer_delete( ti );
return( 1 );
}
ti->tv.tv_secs = 0;
ti->created = 1;
return(0);
}
void timer_delay(Timer_Info *ti, ULONG microsecs)
{
ti->tv.tv_secs = (microsecs/1000000);
ti->tv.tv_micro = (microsecs%1000000);
//printf("waiting for %lds %ldµs\n",ti->tv.tv_secs,ti->tv.tv_micro);
ti->TimerIO->tr_node.io_Command = TR_ADDREQUEST; /* add a new timer request */
/* structure assignment */
ti->TimerIO->tr_time = ti->tv;
/* post request to the timer -- will go to sleep till done */
DoIO((struct IORequest *) ti->TimerIO );
}
void timer_delete(Timer_Info *ti)
{
struct MsgPort *tp;
if ( ! ti->created )
return;
if (ti->TimerIO != 0 )
{
tp = ti->TimerIO->tr_node.io_Message.mn_ReplyPort;
if (tp != 0)
DeletePort(tp);
CloseDevice( (struct IORequest *) ti->TimerIO );
DeleteExtIO( (struct IORequest *) ti->TimerIO );
}
ti->created = 0;
}